<template>
  <a-drawer
    :title="title"
    :width="width"
    placement="right"
    :closable="false"
    @close="close"
    destroyOnClose
    :visible="visible">
    <!-- 审批留言列表（通过mainId筛选） -->
    <cw-approval-message-list
      ref="approvalMessageList"
      :mainId="mainId"
    ></cw-approval-message-list>
    <div class="drawer-footer">
      <a-button @click="handleCancel" style="margin-bottom: 0;">关闭</a-button>
    </div>
  </a-drawer>
</template>

<script>
import CwApprovalMessageList from '../CwApprovalMessageList.vue'

export default {
  name: 'CwApprovalMessageModal',
  components: {
    CwApprovalMessageList
  },
  data() {
    return {
      title: "审批详情",
      width: 800,
      visible: false,
      mainId: null, // 用于接收单据ID，筛选审批记录
      disableSubmit: true // 详情页禁用提交按钮
    }
  },
  methods: {
    // 打开抽屉并传递单据ID
    open(mainId) {
      this.mainId = mainId
      this.visible = true
      // 延迟刷新列表，确保mainId已更新
      this.$nextTick(() => {
        this.$refs.approvalMessageList.loadData()
      })
    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    submitCallback() {
      this.$emit('ok')
      this.visible = false
    },
    handleOk() {
      // 详情页无需提交，预留逻辑
    },
    handleCancel() {
      this.close()
    }
  }
}
</script>

<style lang="less" scoped>
/** Button按钮间距 */
.ant-btn {
  margin-left: 30px;
  margin-bottom: 30px;
  float: right;
}

.drawer-footer {
  position: absolute;
  bottom: -8px;
  width: 100%;
  border-top: 1px solid #e8e8e8;
  padding: 10px 16px;
  text-align: right;
  left: 0;
  background: #fff;
  border-radius: 0 0 2px 2px;
}
</style>